package com.bootx.controller.api;

import com.bootx.common.Result;
import com.bootx.service.RedisService;
import com.bootx.util.JsonUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author black
 */
@RestController
@RequestMapping("/api/lottery")
public class LotteryController {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @PostMapping(value = "/result")
    public Result result(String code){
        if(StringUtils.isBlank(code)){
            code = "10010";
        }
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select id,predictResult,drawCode,DATE_FORMAT(drawTime,'%Y-%m-%d %h:%i:%s') drawTime,sn,win,predictPosition from lotteryrecord where lotteryCode=? order by sn desc;", code);
        return Result.success(maps);
    }

    @PostMapping(value = "/update1")
    public Result update1(Boolean win,String sn){
        int update = jdbcTemplate.update("update lotteryrecord set win=? where sn=?", win, sn);
        return Result.success();
    }
}
